package com.pattern.observer.case02;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@RequiredArgsConstructor
@Slf4j
public class Purchase02Service {
//        implements ApplicationEventPublisherAware {

    @Resource
    private ApplicationEventPublisher applicationEventPublisher;

    public String purchase() {
        long start = System.currentTimeMillis();
        //保存订单（主要业务）
        log.info("-----保存订单-----");
        applicationEventPublisher.publishEvent(new Purchase02Event(this));
        return String.valueOf(System.currentTimeMillis() - start);
    }
//
//    @Override
//    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
//        this.applicationEventPublisher = applicationEventPublisher;
//    }
}
